//
//  BYHotContentViewController.m
//  ZhiHuiLiJiang
//
//  Created by Work on 2018/11/21.
//  Copyright © 2018年 WisdomLijiang. All rights reserved.
//已废弃

#import "BYHotContentViewController.h"
#import "BYHotContentHeardView.h"
#import "BYHotCommentCell.h"
#import "BYHotContentModel.h"
@interface BYHotContentViewController ()<UITableViewDelegate , UITableViewDataSource>

@property (nonatomic ,strong) UITableView * mainTableView;

@property (nonatomic ,strong) BYHotContentModel * model;

@end

@implementation BYHotContentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self hideNavigationBar:YES animated:YES];
    [self.view addSubview:self.mainTableView];
    [self getcontentData:nil];
    NSDictionary *dict1 = @{@"page":@"1",@"limit":@"3",@"mid":self.str};
    [self getCommentData:dict1];

}

-(void)getcontentData:(NSDictionary *)dict{
    BY_kWeakSelf(ws);
    [BYNetworking requestGetOrPostWithType:GET url:[NSString stringWithFormat:@"%@%@",LJURL_Visitor_travelguide_topic,self.str] params:dict success:^(NSInteger code, NSString * _Nonnull msg, id  _Nonnull data) {
        NSDictionary *dataArr = [data objectForKey:@"data"];
        self.model = [BYHotContentModel mj_objectWithKeyValues:dataArr];
        [ws.mainTableView reloadData];
    } fail:^(NSError * _Nonnull error) {
        
    } showHUD:YES];
    
}
-(void)getCommentData:(NSDictionary *)dict{
    BY_kWeakSelf(ws);
    
    [BYNetworking requestGetOrPostWithType:POST url:LJURL_Visitor_travelguide_operweet params:dict success:^(NSInteger code, NSString * _Nonnull msg, id  _Nonnull data) {
        
        NSDictionary *dataArr = [data objectForKey:@"data"];
        self.model = [BYHotContentModel mj_objectWithKeyValues:dataArr];
        [ws.mainTableView reloadData];
    } fail:^(NSError * _Nonnull error) {
        
    } showHUD:YES];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(UITableView *)mainTableView{
    
    if (!_mainTableView) {
        _mainTableView  =[[UITableView alloc]initWithFrame:CGRectMake(0, 64, KSCREEWIDTH, KSCREEHEGIHT -64) style:UITableViewStyleGrouped];
        _mainTableView.delegate =self;
        _mainTableView.separatorStyle = NO;
        _mainTableView.dataSource = self;
        _mainTableView.tableFooterView = [UIView new];
        [_mainTableView registerClass:[BYHotCommentCell class] forCellReuseIdentifier:@"BYHotCommentCell"];
        
        
    }
    return _mainTableView;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    BYHotCommentCell  *cell = [tableView dequeueReusableCellWithIdentifier:@"BYHotCommentCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.heardView.image = [UIImage imageNamed:@"hotDiscussion_1"];
    cell.nameLabel.text = @"yigeren";
    cell.timeLabel.text = @"11-11  11:11";
    cell.contentLabel.text = @"5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A";
    return cell;
}

-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    BYHotContentHeardView*headV=[tableView dequeueReusableHeaderFooterViewWithIdentifier:@"BYHotContentHeardView"];
    if (!headV) {
        headV=[[BYHotContentHeardView alloc]initWithReuseIdentifier:@"BYHotContentHeardView"];
    }
    [headV.imageView sd_setImageWithURL:[NSURL URLWithString:self.model.cover] placeholderImage:[UIImage imageNamed:@""]];
    NSMutableAttributedString * attrString = [[NSMutableAttributedString alloc] initWithData:[self.model.text dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];
//    [attrString addAttribute:NSParagraphStyleAttributeName value:self.paragraphStyle range:NSMakeRange(0, [attrString length])];
    [attrString addAttribute:NSFontAttributeName value:H16 range:NSMakeRange(0, [attrString length])];
    headV.contentLabel.attributedText = attrString;

    return headV;

}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 300;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
